package com.mf.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.entity.Transactions;
import com.mf.service.ITransactionsService;
import com.mf.utils.Result;
import com.mf.vo.transactions.TransactionsListVo;
import com.mf.vo.transactions.TransactionsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 交易表 前端控制器
 * </p>
 *
 * @author mf
 * @since 2024-05-16
 */
@RestController
@RequestMapping("/stock/transactions")
@Tag(name = "交易表")
public class TransactionsController {
    @Resource
    private ITransactionsService transactionsService;

    @PostMapping("/addTransactions")
    @Operation(summary = "新增交易记录")
    public Result<String> addTransactions(@RequestBody Transactions transactions) {
        transactionsService.addTransactions(transactions);
        return Result.success(null);
    }

    @Operation(summary = "批量新增交易记录")
    @PostMapping("/addTransactionsList")
    public Result<Void> addTransactionsList(@RequestBody TransactionsListVo transactionsListVo) {
        return Result.success(transactionsService.addTransactionsList(transactionsListVo));
    }

    @Operation(summary = "根据用户id查询交易记录")
    @GetMapping("/findTransactionsByUserId")
    public Result<List<Transactions>> findTransactionsByUserId(@RequestParam("userId") Integer userId) {
        LambdaQueryWrapper<Transactions> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Transactions::getUserId,userId);
        return Result.success(transactionsService.list(queryWrapper));
    }

    @Operation(summary = "根据用户id查询未卖出股票")
    @GetMapping("/findAwaitSaleByUserId")
    public Result<List<Transactions>> findAwaitSaleByUserId(@RequestParam("userId") Integer userId) {
        return Result.success(transactionsService.findAwaitSaleByUserId(userId));
    }
}
